package grid.celebritysocial;

import java.util.ArrayList;
import java.util.List;

import grid.celebritysocial.logic.HttpXml;
import grid.celebritysocial.session.XmlData;

import org.w3c.dom.*;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;

public class TopActivity extends TabActivity   {


	public XmlData xd = new XmlData();
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.tab);

	    TabHost tabHost = getTabHost();
	    TabHost.TabSpec spec;
	    Intent intent;

		try {
			HttpXml hx = new HttpXml();
			Document doc = hx.getXmldoc("http://gridappweb.appspot.com/user2.xml");


			//profile画像を[XMLDATA]に
			String photoNode[] = {"user","photo"};
			NodeList photoList = hx.getNodeList(doc,photoNode);
			List<String> list = new ArrayList<String>();
			for(int i=0;i < photoList.getLength();i++){
				Node title = photoList.item(i);
				list.add(title.getFirstChild().getNodeValue());
			}
			xd.photoUrl = list;

			//profileNameを[XMLDATA]に
			String nameNode[] = {"user","name"};
			NodeList nameList = hx.getNodeList(doc,nameNode);
			if(nameList.getLength() !=0){
				xd.name = nameList.item(0).getFirstChild().getNodeValue();
			}

			//profileNameJaを[XMLDATA]に
			String nameJaNode[] = {"user","name_ja"};
			NodeList nameJaList = hx.getNodeList(doc,nameJaNode);
			if(nameJaList.getLength() !=0){
				xd.name_ja = nameJaList.item(0).getFirstChild().getNodeValue();
			}

			//profileTELを[XMLDATA]に
			String telNode[] = {"user","tel"};
			NodeList telList = hx.getNodeList(doc,telNode);
			if(telList.getLength() !=0){
				xd.tel = telList.item(0).getFirstChild().getNodeValue();
			}

			//profileMailを[XMLDATA]に
			String mailNode[] = {"user","mail"};
			NodeList mailList = hx.getNodeList(doc,mailNode);
			if(mailList.getLength() !=0){
				xd.mail = mailList.item(0).getFirstChild().getNodeValue();
			}

			//profileBelongを[XMLDATA]に
			String belongNode[] = {"user","belong"};
			NodeList belongList = hx.getNodeList(doc,belongNode);
			if(belongList.getLength() !=0){
				xd.belong = belongList.item(0).getFirstChild().getNodeValue();
			}


			//profileタブ生成
			intent = new Intent(this, ProfileActivity.class);
			intent.putExtra("XMLDATA", xd);
			spec = tabHost.newTabSpec("tab")
		    				.setIndicator("Profile", getResources().getDrawable(R.drawable.games))
		    				.setContent(intent);
		    tabHost.addTab(spec);


		    //各種タブリスト
			String  nodeNameList[] = {"tabs","tab"};
			NodeList tabList = hx.getNodeList(doc,nodeNameList);

			for(int i=0;i < tabList.getLength();i++){
/**				Node tab = tabList.item(i);

				NodeList titleList = ((Element)tab).getElementsByTagName("title");
				Node title = titleList.item(0);
				String type = title.getFirstChild().getNodeValue();

				if(type != null && !type.equals("")){
					if(title.equals("profile")){
						intent = new Intent().setClass(this, ProfileActivity.class);
					    spec = tabHost.newTabSpec("tab"+i)
					    				.setIndicator("Profile")
					    				.setContent(intent);
					    tabHost.addTab(spec);

					}else if(title.equals("blog")){

					}else if(title.equals("twitter")){

					}else if(title.equals("HP")){

					}else if(title.equals("other")){

					}


				}**/



			}




		} catch (Exception e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}










/**













**/

	}
}